package tieba.service.impl;

import java.util.List;
import java.util.Map;

import tieba.dao.IBaseDAO;
import tieba.service.IBaseService;

public abstract class BaseService<T> implements IBaseService<T> {

	private final IBaseDAO<T> baseDao;
	public BaseService(IBaseDAO<T> baseDao) {
		super();
		this.baseDao = baseDao;
	}

	@Override
	public void save(T entity) {
		baseDao.insert(entity);
	}

	@Override
	public void remove(T entity) {
		baseDao.delete(entity);
	}

	@Override
	public void update(T e) {
		baseDao.update(e);

	}

	@Override
	public T findById(int id) {
		return baseDao.selectById(id);
	}

	@Override
	public abstract boolean findByName(String name);


	@Override
	public List<T> getList(Integer pageNum, Integer pageSize, String name,
			String sort) {
		return baseDao.selectList(pageNum, pageSize, name, sort);
	}

	@Override
	public List<T> searchList(Map<String, Object> conditions,
			Integer pageNum, Integer pageSize, String name, String sort) {
		return baseDao.searchList(conditions, pageNum, pageSize, name, sort,
				true);
	}

}
